limsOrderTask.assignmentDetail = {

    getBtnToolbar: function () {
        var _this = this;
        return {
            type: 'btnToolbar',
            items: [{
                type: 'button',
                text: 'GIKAM.BUTTON.SAVE',
                icon: 'save',
                onClick: function () {
                    _this.saveAssignMent('draft');
                }
            }, {
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.SUBMIT',
                icon: 'submit', color: 'success',
                onClick: function () {
                    // Gikam.confirm('GIKAM.BUTTON.CONFIRM', 'GIKAM.TIP.SUBMIT', function () {
                    _this.saveAssignMent("logged");
                    // });
                }
            }, {
                type: 'button',
                text: 'GIKAM.BUTTON.BACK',
                icon: 'back',
                onClick: function () {
                    Gikam.getLastModal().close();
                }
            }]
        }
    },
    baseInfoForm: function () {
        var _this = this;
        var fields = [{
            field: 'methodDesc',
            title: 'T_LIMS_METHOD.METHODDESC',
            validators: ['notEmpty'],
            type: 'choose',
            category: 'test-method',
            single: true,
            onBeforeChoose: function () {
                return {
                    testId_EQ: _this.param.testId
                }
            },
            onAfterChoose: function (row, index) {
                if (!Gikam.isEmpty(row)) {
                    this.setData({
                        testMethodId: row[0].id,
                        methodCode: row[0].ext$.methodcode,
                        methodDesc: row[0].ext$.methoddesc
                    })
                }
            }
        }, {
            field: 'testerId',
            title: 'T_LIMS_ORDER_TASK.TESTER',
            type: 'select',
            category: 'user',
            validators: ['notEmpty'],
            firstBlank: false,
            search: true,
            param: {
                status_EQ: 'activated',
                id_IN: _this.param.testerIds
            },
            onChange: function (field, value, oldvalue, index, text) {
                this.setData({
                    tester: text
                })
            }
        }, {
            field: 'reviewerId',
            title: 'T_LIMS_ORDER_TASK.REVIEWER',
            type: 'select',
            category: 'user',
            validators: ['notEmpty'],
            firstBlank: false,
            search: true,
            param: {
                status_EQ: 'activated',
                id_IN: _this.param.testerIds
            },
            onChange: function (field, value, oldvalue, index, text) {
                this.setData({
                    reviewer: text
                })
            }
        },]
        return {
            type: 'form',
            id: 'order-task-batch-assignment-form',
            columns: 1,
            autoSave: false,
            fields: fields,
            service: 'limsOrderTaskServiceImpl',
            onRendered: function () {
            },
        }
    },

    saveAssignMent: function (status) {
        var formInfo = Gikam.getComp('order-task-batch-assignment-form');
        if (Gikam.isFalse(formInfo.validate())) {
            return;
        }
        var data = Gikam.getComp('order-task-batch-assignment-form').getData();
        // if (data.testerId === data.reviewerId) {
        //     Gikam.alert('检测人复核人不能是同一个人!')
        //     return;
        // }
        data.status = status;
        if (status === 'logged') {
            Gikam.confirm('GIKAM.BUTTON.CONFIRM', 'GIKAM.TIP.SUBMIT', function () {
                Gikam.getLastModal().close(data);
            })
        } else {
            Gikam.getLastModal().close(data);
        }
    },


    create: function () {
        var _this = this;
        Gikam.create('layout', {
            id: 'order-task-assignment-layout',
            renderTo: Gikam.getLastModal().window.$dom,
            center: {
                items: [this.getBtnToolbar(), this.baseInfoForm()]
            }
        });
    },

    init: function (param) {
        this.param = param;
        this.create();
    }
}